package cn.lg.soar.message.api.service;

import cn.lg.soar.common.util.AssertUtil;
import cn.lg.soar.message.api.model.WebSocketDTO;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * @author luguoxiang
 * @date 2022/4/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public interface ISseApi {

    /**
     * 广播消息
     * @param topic
     * @param message
     */
    Collection<Long> broadcast(String topic, String message);

    /**
     * 发送消息
     * @param topic
     * @param dto
     */
    Collection<Long> sendMessage(String topic, WebSocketDTO dto);

    /**
     * 发送消息
     * @param topic
     * @param message
     * @param userIds
     */
    default  Collection<Long> sendMessage(String topic, String message, List<Long> userIds) {
        AssertUtil.notEmpty(userIds, "请指定用户");
        WebSocketDTO dto = new WebSocketDTO();
        dto.setMessage(message);
        dto.setUserIds(userIds);
        return sendMessage(topic, dto);
    }

    /**
     * 发送消息
     * @param topic
     * @param message
     * @param userIds
     */
    default  Collection<Long> sendMessage(String topic, String message, Long...userIds) {
        AssertUtil.notEmpty(userIds, "请指定用户");
        WebSocketDTO dto = new WebSocketDTO();
        dto.setMessage(message);
        dto.setUserIds(Arrays.asList(userIds));
        return sendMessage(topic, dto);
    }

}
